#pragma once
#include <iostream>
#include <string>
#include <ctime>
#include <cstdarg>
#include <unistd.h>
// 错误日志
// 日志等级

#define DEBUG 0   // 调试
#define NORMAL 1  // 正常输出
#define WARNING 2 // 报警
#define ERROR 3   // 出错。但不致命
#define FATAL 4   // 出错，并且致命

const char *to_levelstr(int level)
{
    switch (level)
    {
    case DEBUG:
        return "DEBUG";
    case NORMAL:
        return "NORMAL";
    case WARNING:
        return "WARNING";
    case ERROR:
        return "ERROR";
    case FATAL:
        return "FATAL";
    default:
        return nullptr;
    }
}

void logMessage(int level, const char *format, ...)
{
#define NUM 1024
    char logprefix[NUM];
    snprintf(logprefix,sizeof(logprefix),"[%s][%ld][pid:%d]",to_levelstr(level),(long int)time(nullptr),getpid());

    char logcontent[NUM];
    va_list arg;
    va_start(arg,format);
    vsnprintf(logcontent,sizeof(logcontent),format,arg);

    std::cout << logprefix << logcontent<<std::endl;


}